extends ../inc/layout
block style
	link(rel='stylesheet' href='/assets/vendor/markdown-github.css')
block main
	#main
		#main-inner
			#topnav
				ul
					li 
						a(href='/soft') 首页
					li.sep | 
					li 
						a(href='/tag') 标签
				div(style='clear:both;')
					
			#article-title
				a(href='/soft/#{soft._id}') #{soft.title}

			#article-meta
				作者 #{soft.author.name} | 发布于 #{soft.friendly_create_at}
				if (typeof(current_user) !== 'undefined' && soft.author_id == current_user._id)
					span    ( 
					a(href='/soft/#{soft._id}/update') 编辑 
					span | 
					a(href='javascript:delete_soft(\"#{soft._id}\")') 删除 
					span    )

			#article-tags
				each tag in soft.tags
					a.tag(href='/tag##{tag.name}') #{tag.name}
			
			#article-content.markdown-body 
				textarea#content(style='display:none;') #{soft.content}

			#article-operator
				a#softLost.btn.btn-info(role='button', href='javascript:soft_link_lost(\"#{soft._id}\", \"#{soft.author._id}\")')
					span.glyphicon.glyphicon-thumbs-down    连接失效

block script
	script(src='/assets/vendor/markdown.js')
	script.
		$(function(){
			$('#article-content').html(markdown.toHTML($('#content').val()));
			//- setTimeout(function(){
			//- 	$('#article-content').html(markdown.toHTML($('#content').val()));
			//- }, 0);
		});
		
		var delete_soft = function(soft_id) {
			if(!confirm("文章删除后无法恢复，请确认是否删除此篇文章？")) return;
			var promise = $.post('/soft/' + soft_id + '/delete');
			promise.done(function(data){
				location.href="http://localhost:8888/soft/";
			});
		};

		var soft_link_lost = function(soft_id, author_id){
			var promise = $.post('/soft/message', {soft : soft_id, author : author_id});
			promise.done(function(data){
				console.log(data);
				$('#softLost').attr('disabled', true); 
			});
		}
